<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller
{
        function __construct()
        {
		parent::__construct();
		$this->load->model('User');
	}
        
	function index()
	{
		$this->load->view('layout/header') ; 
    $this->load->view('login');
		$this->load->view('layout/footer');
	}
	
	function profile($id)
        {
                
                $data['user']= $this->User->get_data($id);
                $this->load->view('layout/header') ; 
                $this->load->view('user/profile',$data);
                $this->load->view('layout/footer');
        }
        
        function validate()
        {
            $this->form_validation->set_rules('mail', 'E-mail', 'required|valid_email');
	    $this->form_validation->set_rules('pass1', 'Password', 'required');
            
            if($this->form_validation->run() == FALSE)
		  {
			 $this->load->view('layout/header') ; 
			 $this->load->view('login');
			 $this->load->view('layout/footer');
		  }
		  else
		  {
                        $var = $this->User->ValidateSession($this->input->post());
                            if($var != 0)
				    {
					     $this->session->set_userdata($var);
                                             redirect("/");
				    }
				    else
				    {
                                        $this->load->view('layout/header') ; 
                                        $this->load->view('login');
                                        $this->load->view('layout/footer');
				    }  
                  }
        }
        
        function LogOut()
        {
            $this->session->sess_destroy();
            redirect("/");    
        }
}
